<template>
	<view>
		<view class="headcontent">
			<view class="contentbox" :style="'height:'+headHeight+'rpx;'">
				<image src="../../../static/images/cc/left.png" mode="widthFix" @click="goBack"></image>
			</view>
		</view>
		<view class="banner">
			<swiper :indicator-dots="false" :autoplay="true" :circular="true" :interval="3000" :duration="1000"
				indicator-active-color="#84BD00" indicator-color="rgba(66, 137, 243, 0.2)">
				<swiper-item v-for="(item, index) in con.images" :key="index">
					<view class="swiper-item">
						<image :src="tu(item)" mode="widthFix"></image>
					</view>
				</swiper-item>
			</swiper>
			<view class="shadow"></view>
			<view class="dropBox">
				<view class="drop select"></view>
				<view class="drop"></view>
			</view>
		</view>
		<view class="difficult">
			<image src="../../../static/images/cc/bg.png" mode="widthFix"></image>
			<view class="up">
				<view class="numname">月销 200+ 23收藏</view>
				<view class="upTitle">优惠价格</view>
				<view class="upDetail">
					<view class="upMoney"><text>￥</text>{{con.price}}</view>
					<view class="upName">{{con.title}}</view>
				</view>
				<view class="upThree">
					<view class="upBox">
						<view class="upLname">限制</view>
						<rich-text :nodes="con.desc_1"></rich-text>
						<!-- <view class="upCon">{{}}</view> -->
					</view>
					<view class="upBox">
						<view class="upLname">须知</view>
						<rich-text :nodes="con.desc_2"></rich-text>
						<!-- <view class="upCon">{{con.desc_2}}</view> -->
						<image src="../../../static/images/cc/right.png" mode="widthFix"></image>
					</view>
					<view class="upBox">
						<view class="upLname">保障</view>
						<rich-text :nodes="con.desc_3"></rich-text>
						<!-- <view class="upCon">{{con.desc_3}}</view> -->
						<image src="../../../static/images/cc/right.png" mode="widthFix"></image>
					</view>
				</view>
			</view>
		</view>
		<view class="title">
			<view class="line"></view>
			<view class="titleName">服务详情</view>
		</view>
		<view class="boxCon">
			<rich-text :nodes="con.content"></rich-text>
			<!-- <image src="../../../static/images/cc/an.png" mode="widthFix"></image> -->
		</view>
		<view class="title">
			<view class="line"></view>
			<view class="titleName">购买须知</view>
		</view>
		<view class="boxCon">
			<rich-text :nodes="con.buy_content"></rich-text>
			<!-- <image src="../../../static/images/cc/an2.png" mode="widthFix"></image> -->
		</view>
		<view class="title">
			<view class="line"></view>
			<view class="titleName">适用商户</view>
		</view>
		<view class="shopDetails">
			<view class="headShop">
				<view class="lCon">
					<image :src="tu(con.merchant.avatar)" mode="widthFix"></image>
					<view class="shopMore">
						<view class="shopName">{{con.merchant.shopname}}</view>
						<view class="shopStar">
							<image src="../../../static/images/cc/star1.png" mode="widthFix" v-for="(item,index) in Math.floor(con.merchant.score)" :key="index"></image>
							<image src="../../../static/images/cc/star3.png" mode="widthFix" v-for="(item,index) in Number.isInteger(con.merchant.score) ? 0: 1" :key="index"></image>
							<image src="../../../static/images/cc/star2.png" mode="widthFix" v-for="(item,index) in 5 - Math.ceil(con.merchant.score)" :key="index"></image>
							<view class="anum">{{con.merchant.score}}</view>
							<view class="amoney">￥{{con.merchant.per_capita}}/人</view>
						</view>
						<view class="time">营业中 {{con.merchant.start_time}}-{{con.merchant.end_time}}</view>
					</view>
				</view>
				<view class="call">
					<image @tap='dianhua()' src="../../../static/images/cc/tel.png" mode="widthFix"></image>
					<view>联系商家</view>
				</view>
			</view>
			<view class="titleNames">本店团购</view>
			<view class="list" v-for="(item,index) in con.goods" :key='index'>
				<image :src="tu(item.image)" mode="aspectFill"></image>
				<view class="goods">
					<view class="goodsName">{{item.title}}</view>
					<view class="goodsLave">{{item.description}}</view>
					<view class="evaluate">
						<image src="../../../static/images/cc/okk.png" mode="widthFix"></image>
						<view>{{item.comment}}%好评</view>
					</view>
					<view class="money">
						<view class="price"><text>￥</text>{{item.price}}</view>
						<view class="original">￥{{item.old_price}}</view>
					</view>
					<view class="buy" @tap='qianggou(item.id)'>抢购</view>
				</view>
			</view>
		</view>
		<view class="null"></view>
		<view class="bottomBox">
			<view class="nar">
				<view @tap='mendian(con.shop_id)' class="three">
					<image src="../../../static/images/cc/shop1.png" mode="widthFix"></image>
					<view>门店</view>
				</view>
				<!-- <view class="three">
					<image src="../../../static/images/cc/shop2.png" mode="widthFix"></image>
					<view>购物车</view>
				</view> -->
				<view @tap='shoucang(con.id)' class="three">
					<image :src="con.collect == 0 ? '../../../static/images/cc/shop3.png' : '../../../static/images/cc/shop3_xx.png'" mode="widthFix"></image>
					<view>收藏</view>
				</view>
			</view>
			<view class="operate">
				<!-- <view class="add">加入购物车</view> -->
				<view class="buy" @tap='dinggou()'>立即订购</view>
			</view>
		</view>
	</view>
</template>

<script>
	import wanlshop_config from '@/common/config/config.js';
	let cdnurl = wanlshop_config.cdnurl, appurl = wanlshop_config.appurl, header
	export default {
		data() {
			return {
				headHeight: 0,
				content: "富文本",
				con: {merchant: []}
			};
		},
		methods:{
			dianhua(){
				uni.makePhoneCall({
					phoneNumber: String(this.con.merchant.mobile)
				});
			},
			goBack(){
				uni.navigateBack()
			},
			tu(e){
				if(e){
					if(e.indexOf('http') == -1){
						return `${cdnurl}${e}`	
					}else{
						return e;
					}
				}else{
					return ''
				}
			},
			mendian(shop_id){
				uni.navigateTo({
					url: `/pages/dispatch/shopDetails/shopDetails?id=${shop_id}`
				})
			},
			qianggou(id){
				uni.navigateTo({
					url: `/pages/dispatch/groupBuying/groupBuying?id=${id}`
				})
			},
			shoucang(id){
				uni.showLoading({
					title: 'Loading...'
				})
				uni.request({
					url: `${appurl}/wanlshop/mchomepage/toCollect`,
					data:{
						id: String(id),
						type: String(this.con.collect)
					},
					header,
					complete: res => {
						uni.hideLoading()
						console.log(res)
						if(res.res.code === 1){
							this.con.collect = 1 - this.con.collect
							// this.con = res.data
							// console.log(this.con)
						}else{
							uni.showToast({
							    title: '服务器繁忙',
							    icon: 'none'
							});
						}
					}
				});
			},
			dinggou(){
				
				// JSON.stringify({
				// 	data: [{goods_id:this.con.id, number:1,sku_id:617}]
				// 	order_type: "groups"
				// 	sup_id: ""	
				// })
				// let d_data = JSON.stringify([{goods_id:82, number:1,sku_id:623}]),
				let d_data = JSON.stringify([{goods_id:this.con.id, number:1,sku_id:this.con.sku[0].id}]),
				d_type = 'groups',
				sup_id = ''
				console.log(d_data)
				let canshu = JSON.stringify({
					dianpuming: this.con.merchant.shopname,
					jiage: this.con.vip_price,
					shangpinming: this.con.title,
					shangpinmiaoshu: this.con.description,
					id: this.con.id,
					shangpintu: this.tu(this.con.image),
					shangpinyuanjia: this.con.price
				})
				uni.navigateTo({
					url: `/pages/user/order/addorder?data=${d_data}&d_type=${d_type}&sup_id=`
				})
			}
		},
		onLoad(e){
			header = {token: this.$store.state.user.token}
			uni.request({
				url: `${appurl}/wanlshop/mchomepage/getGoodsInfo`,
				data:{
					id: String(e.id)
				},
				header,
				complete: res => {
					if(res.res.code === 1){
						this.con = res.data
						console.log(this.con)
					}else{
						uni.showToast({
						    title: '服务器繁忙',
						    icon: 'none'
						});
					}
				}
			});
		},
		created() {
			this.headHeight = (uni.getSystemInfoSync().statusBarHeight + 45) * 2
		},
	}
</script>

<style lang="scss">
	page {
		background-color: #F7F7F7;
	}

	.headcontent {
		width: 750rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		position: fixed;
		top: 0;
		z-index: 6666;

		.contentbox {
			width: 750rpx;
			display: flex;
			position: relative;
			align-items: center;

			image {
				width: 50rpx;
				height: 50rpx;
				margin-left: 20rpx;
				position: relative;
				z-index: 999;
			}
		}
	}

	.banner {
		width: 750rpx;
		height: 498rpx;
		position: relative;

		.shadow {
			width: 750rpx;
			height: 498rpx;
			position: absolute;
			top: 0;
			z-index: 1;
			background: linear-gradient(180deg, rgba(0, 0, 0, 0.7) 0%, rgba(0, 0, 0, 0) 40%);
		}

		swiper {
			width: 750rpx;
			height: 498rpx;
			position: relative;



			.swiper-item {
				width: 750rpx;
				height: 498rpx;
				display: flex;
				justify-content: center;
				align-items: center;

				image {
					width: 100%;
					height: 100%;
				}
			}
		}

		.dropBox {
			width: 700rpx;
			margin-left: 34rpx;
			display: flex;
			position: absolute;
			bottom: 60rpx;

			.drop {
				width: 46rpx;
				height: 7rpx;
				background: rgba(255, 255, 255, 0.3);
				border-radius: 50rpx;
				margin-right: 8rpx;
			}

			.select {
				background-color: #fff;
			}
		}
	}

	.difficult {
		width: 750rpx;
		margin-top: -45rpx;
		position: relative;
		display: flex;
		flex-wrap: wrap;

		image {
			width: 750rpx;
			position: absolute;
		}

		.up {
			position: relative;
			// width: 500rpx;

			.numname {
				width: 704rpx;
				margin-right: 46rpx;
				margin-top: 14rpx;
				text-align: right;
				color: #fff;
				font-size: 26rpx;
			}

			.upTitle {
				color: #FB4E2F;
				font-size: 26rpx;
				margin-left: 63rpx;
			}

			.upDetail {
				width: 650rpx;
				margin-left: 50rpx;
				height: 100rpx;
				display: flex;
				align-items: center;
				border-bottom: 1px dashed #D8D8D8;

				.upMoney {
					color: #FB4E2F;
					font-size: 60rpx;

					text {
						font-size: 36rpx;
					}
				}

				.upName {
					font-size: 36rpx;
					color: #3D3D3D;
					margin-left: 68rpx;
				}
			}

			.upThree {
				width: 630rpx;
				margin-left: 60rpx;
				height: 233rpx;
				display: flex;
				flex-wrap: wrap;
				align-content: center;

				.upBox {
					width: 100%;
					display: flex;
					align-items: center;
					padding: 10rpx 0;
					rich-text{
						margin-left: 20rpx;
					}
					.upLname {
						font-size: 26rpx;
						color: #666666;
					}

					.upCon {
						margin-left: 37rpx;
						font-size: 26rpx;
						color: #999999;
					}

					image {
						width: 12rpx;
						height: 12rpx;
						position: relative;
						margin-top: 2rpx;
						margin-left: 10rpx;
					}
				}
			}
		}
	}

	.title {
		width: 664rpx;
		margin-left: 43rpx;
		display: flex;
		align-items: center;
		height: 110rpx;

		.line {
			width: 8rpx;
			height: 34rpx;
			background-color: #FB4E2F;
			border-radius: 50rpx;
		}

		.titleName {
			font-size: 33rpx;
			color: #3D3D3D;
			margin-left: 17rpx;
		}
	}

	.boxCon {
		width: 690rpx;
		background-color: #fff;
		border-radius: 20rpx;
		margin-left: 30rpx;

		image{
			width: 100%;
		}
	}

	.shopDetails {
		width: 690rpx;
		margin-left: 30rpx;
		background-color: #fff;
		border-radius: 20rpx;
		padding-bottom: 30rpx;

		.headShop {
			width: 638rpx;
			margin-left: 26rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding-top: 40rpx;

			.lCon {
				display: flex;
				align-items: center;

				image {
					width: 112rpx;
					height: 112rpx;
					border-radius: 8rpx;
				}

				.shopMore {
					margin-left: 18rpx;
					width: 400rpx;
					display: flex;
					flex-wrap: wrap;
					align-content: space-between;

					.shopName {
						width: 100%;
						font-size: 33rpx;
						color: #3D3D3D;
					}

					.shopStar {
						width: 100%;
						display: flex;
						align-items: center;

						image {
							width: 20rpx;
							height: 20rpx;
							margin-right: 6rpx;
						}

						.anum {
							font-size: 26rpx;
							color: #FB4E2F;
							margin-left: 6rpx;
						}

						.amoney {
							font-size: 26rpx;
							color: #999999;
							margin-left: 28rpx;
						}
					}

					.time {
						width: 100%;
						font-size: 26rpx;
						color: #333333;
					}
				}
			}

			.call {
				width: 104rpx;
				display: flex;
				flex-wrap: wrap;
				justify-content: center;

				image {
					width: 52rpx;
					height: 52rpx;
				}

				view {
					font-size: 26rpx;
					color: #999999;
					margin-top: 6rpx;
				}
			}
		}

		.titleNames {
			margin-left: 26rpx;
			font-size: 26rpx;
			color: #3D3D3D;
			margin-top: 30rpx;
		}

		.list {
			width: 690rpx;
			background-color: #fff;
			border-radius: 20rpx;
			display: flex;
			margin-top: 36rpx;

			image {
				width: 200rpx;
				height: 200rpx;
				border-radius: 10rpx;
				margin-left: 26rpx;
			}

			.goods {
				width: 416rpx;
				margin-left: 22rpx;
				display: flex;
				align-content: space-between;
				flex-wrap: wrap;
				position: relative;

				.goodsName {
					width: 100%;
					font-size: 30rpx;
					color: #3D3D3D;
				}

				.goodsLave {
					width: 100%;
					font-size: 26rpx;
					color: #999999;
				}

				.evaluate {
					width: 157rpx;
					height: 39rpx;
					border-radius: 50rpx;
					display: flex;
					justify-content: center;
					align-items: center;
					background-color: #F7F7F7;

					image {
						width: 20rpx;
						height: 20rpx;
						margin-left: 0 !important;
					}

					view {
						font-size: 22rpx;
						color: #666666;
						margin-left: 6rpx;
					}
				}

				.money {
					width: 100%;
					display: flex;
					align-items: flex-end;

					.price {
						color: #FB4E2F;
						font-size: 36rpx;

						text {
							font-size: 26rpx;
						}
					}

					.original {
						font-size: 26rpx;
						color: #999999;
						margin-left: 10rpx;
						text-decoration: line-through;
						margin-bottom: 4rpx;
					}
				}

				.buy {
					position: absolute;
					bottom: 0;
					right: 0;
					width: 136rpx;
					height: 65rpx;
					background-color: #FB4E2F;
					display: flex;
					justify-content: center;
					align-items: center;
					border-radius: 50rpx;
					font-size: 26rpx;
					color: #fff;
				}
			}
		}
	}

	.bottomBox {
		width: 750rpx;
		height: 120rpx;
		background: #FFFFFF;
		box-shadow: 0px 17rpx 50rpx 0px rgba(0, 0, 0, 0.13);
		position: fixed;
		bottom: 0;
		padding-bottom: 0;
		display: flex;
		justify-content: space-between;
		align-items: center;

		// 334
		.nar {
			width: 334rpx;
			display: flex;
			justify-content: space-around;

			.three {
				width: 100rpx;
				display: flex;
				justify-content: center;
				align-items: center;
				flex-wrap: wrap;

				image {
					width: 62rpx;
					height: 62rpx;
				}

				view {
					width: 100rpx;
					text-align: center;
					font-size: 20rpx;
					color: #3D3D3D;
				}
			}
		}

		.operate {
			width: 396rpx;
			height: 82rpx;
			margin-right: -10rpx;
			display: flex;

			.add {
				width: 50%;
				display: flex;
				justify-content: center;
				align-items: center;
				font-size: 30rpx;
				background: linear-gradient(270deg, #FBBE2F 0%, #FBE02F 100%);
				border-radius: 50rpx 0px 0px 50rpx;
				color: #fff;
			}

			.buy {
				width: 80%;
				display: flex;
				justify-content: center;
				align-items: center;
				font-size: 30rpx;
				background: linear-gradient(270deg, #FB4E2F 0%, #FBA92F 74%);
				// border-radius: 0rpx 50rpx 50rpx 0rpx;
				border-radius: 50rpx;
				color: #fff;
			}
		}
	}

	.null {
		width: 750rpx;
		height: 160rpx;
		padding-bottom: env(safe-area-inset-bottom);
	}
</style>